import { getConfig } from '@libs/common/utils';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';

import { DingdingModule } from '@/dingding/dingding.module';

import { AuthController } from './auth.controller';
import { Providers } from './auth.providers';
import { AuthService } from './auth.service';
import { JwtStrategy } from './strategies/auth.strategy';

@Module({
  imports: [
    PassportModule,
    DingdingModule,
    JwtModule.registerAsync({
      useFactory() {
        const { JWT } = getConfig();
        return {
          secret: JWT.secret,
          signOptions: {
            expiresIn: JWT.access_token_expires_time,
          },
        };
      },
    }),
  ],
  providers: [...Providers, AuthService, JwtStrategy],
  controllers: [AuthController],
})
export class AuthModule {}
